home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / datatypes / playdt13.lha / PlayDT / PlayDT-src / UseCli.c < prev    next >
C/C++ Source or Header  |  1997-06-05  |  4KB  |  165 lines

  1. /****************************************************************
  2.  *
  3.  * $VER: UseCli.c 1.3 (4.6.97) Tak Tang (tst92@ecs.soton.ac.uk)
  4.  *
  5.  * Copyright © 1997 Tak Tang
  6.  *
  7.  * You may use any part of this source code in your own programs
  8.  * provided that it is not called PlayDT.
  9.  *
  10.  ******************************************************************
  11.  *
  12.  */
  13.  
  14.  
  15. /**** Soft definitions ****/
  16.  
  17. #define TEMPLATE        "FILE/M,REQUESTER/S"
  18. #define OPT_FILE        0
  19. #define OPT_REQ         1
  20. #define OPT_COUNT       2
  21.  
  22.  
  23. /**** Header files ****/
  24.  
  25. #include "PlayDT.h"
  26.  
  27. #include <clib/dos_protos.h>
  28. #include <clib/datatypes_protos.h>
  29.  
  30. #include <pragmas/dos_pragmas.h>
  31. #include <pragmas/datatypes_pragmas.h>
  32.  
  33. #include <string.h>
  34.  
  35.  
  36. /****** UseCLI *****************************************************
  37. *
  38. *   NAME
  39. *       UseCLI - call PlayFile for each arg passed by cli, or call asl
  40. *
  41. *   SYNOPSIS
  42. *       UseCLI ( GlobalData )
  43. *
  44. *       UseCLI ( struct GlobalData * );
  45. *
  46. *   FUNCTION
  47. *       UseCli attempts to play sound files specified on the command
  48. *       line.  It accepts multiple arguments, each of which
  49. *       may be a pattern (eg #?.(8svx|wav) ).  File names containing
  50. *       spaces must be enclosed in double quotes.
  51. *
  52. *       If no files are specified, or if the REQUESTER switch is
  53. *       supplied, it will call the ASL file requester
  54. *
  55. *   INPUTS
  56. *       GlobalData -
  57. *
  58. *   RESULT
  59. *       None
  60. *
  61. *   EXAMPLE
  62. *
  63. *   NOTES
  64. *       Does not descend directories.
  65. *
  66. *   BUGS
  67. *
  68. *   SEE ALSO
  69. *       UseWB.c/UseWB(), UseASL.c/UseAsl(), PlayFile.c/PlayFile()
  70. *
  71. *****************************************************************************
  72. *
  73. */
  74.  
  75.  
  76. void UseCLI(struct GlobalData *gd)
  77. {
  78.   ULONG opts[OPT_COUNT];
  79.   struct RDArgs *rdargs;
  80.   char *curarg, **argptr;
  81.   ULONG rc;
  82.   BPTR op, newlock, oldlock;
  83.   UBYTE errbuff[80];
  84.   struct AnchorPath __aligned ua;
  85.  
  86.   /* parse command line */
  87.   memset (opts, 0, sizeof(opts));
  88.   rdargs = ReadArgs (TEMPLATE, (LONG *)opts, NULL);
  89.   if ( NULL!= rdargs )
  90.   {
  91.  
  92.     if ( NULL != opts[OPT_FILE] )
  93.     {
  94.       /* for each argument ... */
  95.       argptr=(char **)opts[OPT_FILE];
  96.       while ( (curarg=*argptr++) && (FALSE==gd->UserStop))
  97.       {
  98.         memset(&ua, 0, sizeof(struct AnchorPath));
  99.         /* call pattern matching */
  100.         rc=MatchFirst(curarg, &ua);
  101.         /* for each match ... */
  102.         for ( ; (0==rc) && (FALSE==gd->UserStop) ; )
  103.         {
  104.           if (ua.ap_Info.fib_DirEntryType <0)
  105.           {
  106.             /* go to the directory */
  107.             newlock = DupLock(ua.ap_Current->an_Lock);
  108.             oldlock = CurrentDir(newlock);
  109.  
  110.             /* play the file */
  111.             if ( 0!=PlayFile(gd, ua.ap_Info.fib_FileName) )
  112.             {
  113.               rc = IoErr();
  114.             } /* if PlayFile() OK */
  115.  
  116.             CurrentDir(oldlock);
  117.             UnLock(newlock);
  118.           } /* if is file */
  119.  
  120.           if (0==rc)
  121.           {
  122.             rc=MatchNext(&ua);
  123.           }
  124.         } /* while */
  125.  
  126.         /* there was a problem, so tell the user */
  127.         if ( (rc != 0) &&
  128.              (rc != ERROR_NO_MORE_ENTRIES) &&
  129.              (rc != ERROR_BREAK) )
  130.         {
  131.           op = Output();
  132.           FPrintf(op,"%s: ", ua.ap_Info.fib_FileName);
  133.           if (rc >= DTERROR_UNKNOWN_DATATYPE)
  134.           {
  135.             FPrintf(op,GetDTString (rc), ua.ap_Info.fib_FileName);
  136.           }
  137.           else
  138.           {
  139.             Fault (rc, NULL, errbuff, sizeof (errbuff));
  140.             FPrintf(op,"%s",errbuff);
  141.           }
  142.           FPrintf(op,"\n");
  143.         } /* if */
  144.  
  145.         MatchEnd(&ua);
  146.       } /* while arg++ */
  147.     } /* if opts[OPT_FILE] */
  148.  
  149.     if ( (NULL == opts[OPT_FILE]) || (NULL!=opts[OPT_REQ]) )
  150.     {
  151.       UseASL(gd);
  152.     } /* if */
  153.  
  154.     FreeArgs (rdargs);
  155.   } /* if NULL != rdargs */
  156.   else
  157.   {
  158.     PrintFault (IoErr(), MSG_FAILED);
  159.   } /* if NULL == rdargs */
  160. } /* UseCLI */
  161.  
  162.  
  163. /**** End of file ****/
  164.  
  165.